/**
 * 
 */
package com.woniuxy.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.woniuxy.pojo.Member;
import com.woniuxy.pojo.User;

/**
 * @author Fz
 * @date 2019年8月2日 下午3:01:43
 * @param 
 * @return
 */

public interface UserMapper {

	@Select("select * from user where ustate like '%admin'")
	List<User> getAllAdmin();
	  
	@Select("select * from user where account=#{account}")
	User findUserByAccount(String account);

	@Insert("insert into user values(default,#{account},#{pass},default,#{ustate})")
	int addAmin(User user);

	@Update("update user set ustate=#{ustate} where uid=#{uid}")
	int updateAdmin(User user);

	@Delete("delete from user where uid=#{uid}")
	int delAdmin(String uid);

	@Select("select * from user where account like #{message} or ustate like #{message}")
	List<User> findA(String message);

	@Insert("insert into member(mnumber,mname,mtel,mtype) values(#{mnumber},#{mname},#{mtel},#{mtype})")
	int regmember(String mnumber, String mname, String mtel, String mtype);
	
	@Select("select mid from member where mnumber=#{mnumber}")
	int findMidByMnumber(String mnumber);

	@Insert("insert into user(account, pass, mid, ustate) values(#{account}, #{pass}, #{mid}, #{ustate})")
	int register(String account, String pass, int mid,String ustate);
	@Select("SELECT * FROM `user` INNER JOIN member WHERE `user`.MID=member.mid AND uid=#{uid}")
	@Results({
		@Result(id=true,column="uid",property="uid"),
		@Result(column="account",property="account"),
		@Result(column="pass",property="pass"),
		@Result(column="ustate",property="ustate"),
		@Result(column="mid",property="member",one=@One(
				select="findMember"
				))
	})
	public User FindIdByUser(Integer uid);
	@Select("select *from member where mid=#{mid}")
	public Member findMember(Integer mid);
	
	@Select("select ustate from user where uid=#{uid}")
	String FindSf(Integer uid);
	
	@Select("select * from user where mid=(select mid from member where mtel=#{mtel})")
	User findUserByTel(String mtel);

}
